﻿Imports System
Imports System.IO
Imports System.Data.OleDb
Imports System.Data

Imports System.Net.Mail


Namespace Arwani
    Partial Class Requestforservice
        Inherits System.Web.UI.Page
        Dim strNotSendAgain As String = ""
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack Then
                If Request.Cookies("Code") Is Nothing Then

                    Response.Redirect("index.aspx")
                Else
                    txtCompanyName.Text = Session("CompanyName")

                End If
            End If
        End Sub
       

        Protected Sub lnkSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSend.Click



            SaveRequestServiceData()
            Dim strMessage As String = ""
            strMessage = "Following information has been sent in the Request Service form<br>"
            strMessage &= "Contact Name : " & Me.txtContactName.Text & "<Br>"
            strMessage &= "Company Name : " & Me.txtCompanyName.Text & "<Br>"
          
            strMessage &= "E-Mail : " & Me.txtEmail.Text & "<Br>"
            Dim title As [String] = "Request Service - Arwani Trading Website "
            Dim toAccount As [String] = " ae.arwani@gmail.com"
            'Dim toAccount As [String] = " sahilk@nascenture.com"
            Dim MyHost As [String] = "smtp.gmail.com"
            Dim MySMTPPort As [String] = "587"
            Dim MySMTPSSL As [String] = "true"
            Dim fromAddr As [String] = txtEmail.Text.ToString()
            'Email Address of Sender
            Dim smtpMssg As New System.Net.Mail.MailMessage()
            smtpMssg.From = New MailAddress(fromAddr)
            If toAccount.Contains(",") Then
                Dim tos As String() = toAccount.Split(","c)
                For i As Integer = 0 To tos.Length - 1
                    If tos(i) = "," OrElse tos(i) = "" Then
                    Else
                        smtpMssg.[To].Add(New MailAddress(tos(i).Replace(",", "")))
                    End If
                Next
            Else
                smtpMssg.[To].Add(New MailAddress(toAccount))
            End If
            smtpMssg.Subject = title
            smtpMssg.Body = strMessage
            smtpMssg.IsBodyHtml = True
            Dim smtpClient As New System.Net.Mail.SmtpClient(MyHost, Convert.ToInt32(MySMTPPort))
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
            If MySMTPSSL = "true" Then
                smtpClient.EnableSsl = True
            End If
            Try
                smtpClient.Send(smtpMssg)
            Catch ex As Exception
                Throw New Exception("Email not sent | Reason: [" + ex.Message & "]")
            End Try
            Me.lblErrorMessage.Visible = True
            Me.txtCompanyName.Text = String.Empty
            Me.txtContactName.Text = String.Empty
           
            Me.txtEmail.Text = String.Empty

            Response.Redirect("CustomerInvoice.aspx")


        End Sub
        Protected Sub SaveRequestServiceData()
            Dim arwCon1 As New ArwaniController
            Dim strQ As String = "Insert into RequestService (ContactName,CompanyName,OfficePhoneNumber,MobilePhoneNumber,EmailID) values ('" & txtContactName.Text & "','" & txtCompanyName.Text & "','','','" & txtEmail.Text & "')"
            arwCon1.ExecuteNonQuery(strQ)

        End Sub

    End Class
End Namespace